<%@ page language="java" contentType="text/html; charset=UTF-8"	 pageEncoding="UTF-8"%>
<%@ include file="../include/laypublic.jsp"%>
<!DOCTYPE html>
<html>
<head>
  <title>业务承接单新增</title>
</head>
<style>
	.fieldset{
		margin-top: 5px;
		margin-bottom: 0px
	}
	.layui-legend{
		background-color:#5fb878;
		font-size:15px !important;
		width:140px;
	}
	.layui-form-item {
	    margin-bottom: 5px;
	    clear: both;
	    *zoom: 1;
	}
	.layui-form-label{width: 180px;}
</style>
<body>
<div class="layui-fluid">
    <div class="layui-card">
	    <div class="layui-tab-item layui-show">
	    	<div style="padding-top:15px;">&nbsp;</div>
			<form class="layui-form" id="addInfo_form" lay-filter="add_info_from">
				<fieldset class="layui-elem-field layui-field-title fieldset"  id="baseInfo">
				  <legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">项目基础信息  ></legend>
				  <div style="margin-top:20px">
				  	<div class="layui-form-item">
				  		<div class="layui-inline">
					      	<label class="layui-form-label">项目名称</label>
					      	<div class="layui-input-inline">
					        	<select name="id" lay-filter="add_select_proId" lay-verify="required" lay-search>
		              				<option value="">请选择-项目名称</option>
				              		<c:if test="${not empty disclosePros }">
				              			<c:forEach items="${disclosePros}" var="disclosePro">
				              				<option value="${disclosePro.id }">${disclosePro.proName }</option>
					            		</c:forEach>
				              		</c:if>
				              	</select>
						        <input type="hidden" name="proName">
					      	</div>
					    </div>
					    <div class="layui-inline">
					    	<label class="layui-form-label">项目类型</label>
				      		<div class="layui-input-inline">
						        <input type="text" value="PPP项目" style="border:0px;" readonly="readonly" class="layui-input">
						        <input type="hidden" name="types" value="1">
				      		</div>
					    </div>
					    <div class="layui-inline">
					    	<label class="layui-form-label">项目编号</label>
				      		<div class="layui-input-inline">
						        <input type="text" name="proCode" style="border:0px;" readonly="readonly" class="layui-input">
				      		</div>
					    </div>
				    </div>
				  	<div class="layui-form-item">
				  		<div class="layui-inline">
					      	<label class="layui-form-label">申请公司</label>
					      	<div class="layui-input-inline">
					      		<input type="hidden" name="proAcceptOrgId" value="${bindOrgId}">
								<input type="text" value="${bindOrgName}" style="border:0px;" readonly="readonly" class="layui-input">
					      	</div>
					    </div>
					    <div class="layui-inline">
					    	<label class="layui-form-label">申请部门</label>
				      		<div class="layui-input-inline">
				      			<input type="hidden" name="proAcceptDeptId" value="${bindDeptId}">
								<input type="text" value="${bindDeptName}" style="border:0px;" readonly="readonly" class="layui-input">
				      		</div>
					    </div>
					    <div class="layui-inline">
					    	<label class="layui-form-label">申请人</label>
				      		<div class="layui-input-inline">
				        		<input type="hidden" name="setupHrStaffApplyId" value="${SESSION_KEY_USER_DETAIL.hrStaffId }">
				        		<input type="text" name="setupStaffName" value="${SESSION_KEY_USER_DETAIL.realName }" readonly="readonly" style="border:0px" class="layui-input">
				      		</div>
					    </div>
				    </div>
				  	<div class="layui-form-item">
				  		 <div class="layui-inline">
					    	<label class="layui-form-label">项目城市</label>
				      		<div class="layui-input-inline">
				        		<input type="hidden" name="sgCityId">
				        		<input type="text" name="sgCityName" readonly="readonly" style="border:0px" class="layui-input">
				      		</div>
					    </div>
				  		<div class="layui-inline">
					    	<label class="layui-form-label">营销经理</label>
				      		<div class="layui-input-inline">
				        		<input type="hidden" name="hrStaffMktId">
				        		<input type="text" name="hrStaffName" readonly="readonly" style="border:0px" class="layui-input">
				      		</div>
					    </div>
				    </div>
		  		</div>
			</fieldset>
			<fieldset class="layui-elem-field layui-field-title fieldset"  id="investInfo">
		  		<legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">承建信息 ></legend>
			  	<div style="margin-top:20px">
			  		<div class="layui-form-item">
					    <div class="layui-inline">
					    	<label class="layui-form-label">承接方式</label>
				      		<div class="layui-input-inline">
					      		<select name="takeType" lay-filter="add_select_takeType" lay-verify="required">
					              	<option value="">请选择-承接方式</option>
					              	<option value="1">建投自接</option>
					              	<option value="2">产业联合</option>
			              		</select>
				      		</div>
					    </div>
					    <div class="layui-inline">
					    	<label class="layui-form-label">指标占比（%）</label>
				      		<div class="layui-input-inline">
					      		<input type="text" name="normPercent" id="normPercent" onblur="calcSubTotalCae();" maxlength="11" lay-verify="required|floatNumber" class="layui-input">
				      		</div>
					    </div>
					    <div class="layui-inline">
					    	<label class="layui-form-label">中标通知书日期</label>
				      		<div class="layui-input-inline">
					      		<input type="text" class="layui-input" id="sent-laydate-notice" name="noticeDate" lay-verify="required" readonly>
				      		</div>
					    </div>
					</div>
			  		<div class="layui-form-item">
					    <div class="layui-inline">
					    	<label class="layui-form-label">合作周期（年）</label>
				      		<div class="layui-input-inline">
					      		<input type="text" name="workYears" readonly="readonly" style="border:0px" class="layui-input">
				      		</div>
					    </div>
					    <div class="layui-inline">
					      	<label class="layui-form-label">建设周期（年）</label>
					      	<div class="layui-input-inline">
					        	<input type="text" name="buildYears" readonly="readonly" style="border:0px" class="layui-input">
					      	</div>
					    </div>
					    <div class="layui-inline">
					      	<label class="layui-form-label">运营周期（年）</label>
					      	<div class="layui-input-inline">
					        	<input type="text" name="omYears" readonly="readonly" style="border:0px" class="layui-input">
					      	</div>
					    </div>
				    </div>
			  	</div>
			</fieldset>
			<fieldset class="layui-elem-field layui-field-title fieldset" id="houseInfo">
		  		<legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">项目资金信息  ></legend>
			  	<div style="margin-top:20px">
			  		<div class="layui-form-item">
			  			<div class="layui-inline">
					      	<label class="layui-form-label">总投资额（万元）</label>
					      	<div class="layui-input-inline">
					        	<input type="text" name="sumAmount" readonly="readonly" style="border:0px" class="layui-input">
					      	</div>
					    </div>
					    <div class="layui-inline">
					      	<label class="layui-form-label">建安工程总费用（万元）</label>
					      	<div class="layui-input-inline">
					        	<input type="text" id="sumCae" name="sumCae" readonly="readonly" style="border:0px" class="layui-input">
					      	</div>
					    </div>
					    <div class="layui-inline">
					    	<label class="layui-form-label">建安指标小计（万元）</label>
				      		<div class="layui-input-inline">
					      		<input type="text" id="subtotalCae" name="subtotalCae" readonly="readonly" style="border:0px" class="layui-input">
				      		</div>
					    </div>
				    </div>
				    <fieldset class="layui-elem-field layui-field-title fieldset"  id="creditInfo">
		  				<legend style="margin-left:40px;font-size:15px;font-weight:bold;">投资构成  ></legend>
			  			<div style="margin-top:20px">
			  				<div class="layui-form-item">
							    <div class="layui-inline">
							    	<label class="layui-form-label">建安工程费（万元）</label>
						      		<div class="layui-input-inline">
							      		<input type="text" id="costCae" name="costCae" readonly="readonly" style="border:0px" class="layui-input">
						      		</div>
							    </div>
							    <div class="layui-inline">
							      	<label class="layui-form-label">设备购置工程费（万元）</label>
							      	<div class="layui-input-inline">
							        	<input type="text" id="deviceCost" name="deviceCost" readonly="readonly" style="border:0px" class="layui-input">
							      	</div>
							    </div>
							    <div class="layui-inline">
							      	<label class="layui-form-label">预备费（万元）</label>
							      	<div class="layui-input-inline">
							        	<input type="text" id="inReadyCost" name="inReadyCost" readonly="readonly" style="border:0px" class="layui-input">
							      	</div>
							    </div>
						    </div>
			  				<div class="layui-form-item">
							    <div class="layui-inline">
							    	<label class="layui-form-label">建设期利息（万元）</label>
						      		<div class="layui-input-inline">
							      		<input type="text" name="periodInterest" readonly="readonly" style="border:0px" class="layui-input">
						      		</div>
							    </div>
							    <div class="layui-inline">
							      	<label class="layui-form-label">铺底流动资金（万元）</label>
							      	<div class="layui-input-inline">
							        	<input type="text" name="fluidCapital" readonly="readonly" style="border:0px" class="layui-input">
							      	</div>
							    </div>
							    <div class="layui-inline">
							      	<label class="layui-form-label">工程建设其他费（万元）</label>
							      	<div class="layui-input-inline">
							        	<input type="text" name="otherCost" readonly="readonly" style="border:0px" class="layui-input">
							      	</div>
							    </div>
						    </div>
			  				<div class="layui-form-item">
							    <div class="layui-inline">
							    	<label class="layui-form-label">其中：征地拆迁费（万元）</label>
						      		<div class="layui-input-inline">
							      		<input type="text" name="moveOutCost" readonly="readonly" style="border:0px" class="layui-input">
						      		</div>
							    </div>
						    </div>
			  			</div>
			  		</fieldset>
			  	</div>
			</fieldset>
			<fieldset class="layui-elem-field layui-field-title fieldset"  id="creditInfo">
		  		<legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">项目其他信息  ></legend>
			  	<div style="margin-top:20px">
			  		<div class="layui-form-item">
					    <div class="layui-inline">
					    	<label class="layui-form-label">其他说明</label>
				      		<div class="layui-input-inline">
					      		<textarea name="otherRemark" maxlength="500" placeholder="请输入其他说明" lay-verify="required" class="layui-textarea" style="width:899px;height:90px;"></textarea>
				      		</div>
					    </div>
				    </div>
			  	</div>
			</fieldset>
			<div class="layui-form-item" style="position: fixed ! important; right: 30px; bottom:45%;z-index:10000;">
				<div class="layui-input-block">
		      		<button class="layui-btn layui-bg-blue layui-btn-normal layui-btn-lg  layui-btn-radius" type="button" lay-submit lay-filter="addInfo_form_submit" id="addInfo_form_submit">
		      		<i class="layui-icon layui-icon-ok layuiadmin-button-btn"></i>
		      		提交
		      		</button>
		      	</div>
		    </div>
			</form>
  		</div>
	</div>
</div>
  <script>
	//静态资源路径前缀
	var staticPath = '${fileHttpPre}';
	var stateJSON = <infopub:dicJson groupNo="A00010028" />;
	
  layui.config({
    base: '${ctx}/resources/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'set', 'upload', 'element', 'laydate'], function(){
    var $ = layui.$
    ,form = layui.form
    ,element = layui.element
    ,laydate = layui.laydate
    ,upload = layui.upload;
    
    laydate.render({
	      elem: '#sent-laydate-notice'
	      ,trigger: 'click'
    });
 	// 正则校验
	form.verify({
		//验证汉字
	    CHS:[
	    	/^[\u0391-\uFFE5]+$/
	    	,'只能输入汉字'
	  	],
	  	//大于0的正整数
	  	intNumber:[
			/^[1-9]\d*$/
			,'请输入正确的数字'
	  	],
	  	//数字只能有两位小数
	  	floatNumber:[
			/^([-]?)([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
			,'请输入正确的数字'
	  	],
	  	//数字大于等于0，并只能有两位小数
	  	floatAmount:[
			/^([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
			//var pattern=/^((\d+\.\d*[1-9]\d{1})|(\d*[1-9]\d*\.\d{2}))$/; 
			,'请输入正确的数字'
	  	]
	});
    
  	//项目名称select监听
    form.on('select(add_select_proId)', function(data){
    	var id = data.value;
    	if(id == null || id == ''){
    		return;
    	}
    	//获取公司下的所有部门
		$.ajax({
			type : "POST", //提交方式  
			url : "${ctx}/disclosePro/getDiscloseProById",//路径  
			data : {
				"id" :id
			},//数据，这里使用的是Json格式进行传输  
			success : function(result) {//返回数据根据结果进行相应的处理 
				if(result.flag==true){
					form.val('add_info_from',result.discloseProVo); // 填充原值
					calcSubTotalCae();
				}else{
					layer.msg('数据通信异常~',{icon: 0});
				}
			} 
		});
	});
  	
  	//承接方式select监听
    form.on('select(add_select_takeType)', function(data){
    	var takeType = data.value;
    	if(takeType == null || takeType == ''){
    		return;
    	}
    	if(takeType == '1'){//建投自接
    		$("#normPercent").css("border","0px");
    		$("#normPercent").attr("readonly","readonly");
    		$("#normPercent").val(100);
    		calcSubTotalCae();
    		form.render();
    	}else if(takeType == '2'){
    		$("#normPercent").val('');
    		$("#normPercent").removeAttr("readonly");
    		$("#normPercent").removeAttr("style");
    	}
	});
  	
   	//监听提交
  	form.on('submit(addInfo_form_submit)', function(data){
  		$("#addInfo_form_submit").removeAttr("lay-submit").removeClass("layui-bg-blue").addClass("layui-btn-disabled");
  		layer.load();
       	//提交 Ajax 成功后，静态更新表格中的数据
       	$.ajax({
           	type : 'post',
			url : basePath + '/proAccept/save',
           	data: $('#addInfo_form').serialize(),
			success:function(result){
				if(result.success){
					layer.closeAll('loading'); //关闭loading
					layer.msg('提交单据成功~',{icon: 1});
					//两秒后关闭当前页面
					setTimeout(function(){
						/**
						 * 查找父菜单，并刷新
						 */
						var topDoc = $(window.top.document);
						var path = basePath + '/proAccept/list';
						// 获取页面名称
						var name = topDoc.find(".layui-nav-item [lay-href^='" + path + "']").text();
						if(name == '' || name == null){
							name = '业务承接单';
						}
						window.parent.layui.index.openTabsPage(path, name);
						var iframe = window.parent.layui.admin.tabsBody(window.parent.layui.admin.tabsPage.index).find(".layadmin-iframe");
						iframe[0].contentWindow.location.reload(true);
						
						/**
						 * 关闭当前页
						 */
						var currPath = basePath + '/proAccept/add';
						var layid = topDoc.find("li[lay-id^='" + currPath + "']").attr('lay-id');
						window.parent.layui.element.tabDelete('layadmin-layout-tabs', layid);//关闭当前页
				        }, 2000);
				}else{
					layer.closeAll('loading'); //关闭loading
  					$("#addInfo_form_submit").removeClass("layui-btn-disabled").addClass("layui-bg-blue").attr("lay-submit","");
					layer.msg(result.msg,{icon: 7});
			  	}
			}
       	});
   	});  
 	// data-type事件
    $('.layui-btn.layuiadmin-btn-admin').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
  	
  });
  
	//计算建安指标小计
	function calcSubTotalCae(){
		var $ = layui.$;
		var normPercent = $("#normPercent").val();
		if(normPercent == ''){
			return;
		}
		var sumCae = $("#sumCae").val();
		var totalAmount = 0;
		var totalCae = 0;
		if(sumCae != '' && parseFloat(sumCae) > 0){
			totalAmount = parseFloat(totalAmount) + parseFloat(sumCae);
			totalAmount = totalAmount.toFixed(2);
		}
		if(totalAmount > 0){
			totalCae = parseFloat(totalAmount)*parseFloat(normPercent)/100;
			totalCae = totalCae.toFixed(2);
		}
		$("#subtotalCae").val(totalCae);
	}
  </script>
</body>
</html>

